﻿
$(function(){
	var pathName=window.document.location.pathname;
	var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
	
	$('.ececk_warning').hide();
	
	//动态注销或激活注册按钮
	$('.input').on('change', function() {
		var flag = 1;
		$('.input').each(function() {
			if($(this).val() == "") {
				flag = 2;
			}
		});
		if(flag == 1) {
			$('#regist').removeAttr("disabled");
		} else {
			$('#regist').attr("disabled",'disabled');
		}
	});
	
	//对空输入框给出提示
	$('.input').on('change', function() {
		var inputValue = $(this).val();
		if(inputValue == "") {
			$(this).parent().next().eq(0).show();
		} else {
			$(this).parent().next().eq(0).hide();
		}
	});
	
	//判断两次密码是否一致
	$('#passwordAgain').on('change', function() {
		var password = $('#password').val();
		var passwordAgain = $('#passwordAgain').val();
		if(passwordAgain != password && password != "" && passwordAgain != "") {
			$('#passwordts').text('前后输入密码不一致');
			$('#passwordts').parent().show();
			$('#regist').attr("disabled",'disabled');
		} else if(passwordAgain == password && password != "" && passwordAgain != "") {
			$('#passwordts').parent().hide();
		} else if(passwordAgain == "") {
			$('#passwordts').text('请填写确认密码');
		} else {
			$('#passwordts').text('前后输入密码不一致');
		}
	});
	$('#password').on('change', function() {
		var password = $('#password').val();
		var passwordAgain = $('#passwordAgain').val();
		if(passwordAgain != password && password != "" && passwordAgain != "") {
			$('#passwordts').text('前后输入密码不一致');
			$('#passwordts').parent().show();
			$('#regist').attr("disabled",'disabled');
		} else if(passwordAgain == password && password != "" && passwordAgain != "") {
			$('#passwordts').parent().hide();
		} else if(passwordAgain == "") {
			$('#passwordts').text('请填写确认密码');
		} else {
			$('#passwordts').text('前后输入密码不一致');
		}
	});
	
	//异步判断账号是否重复
	$('#account').on('change', function() {
		var accountValue = $('#account').val();
		if(accountValue != "") {
			$.ajax({
				url:projectName + "/User/haveSameAccount",
				type:"post",
				async:true,
				data:{"userAccount" : accountValue},
//				dataType:"json",
				success:function (data) {
					if(data == "yes") {
						$('#accountts').text('该账号已被注册');
						$('#accountts').parent().show();
						$('#regist').attr("disabled",'disabled');
					} else {
						$('#accountts').text('账号不能为空');
						$('#accountts').parent().hide();
					}
				}
			});
		} else {
			$('#accountts').text('账号不能为空');
		}
	});
});